/**
 * Copyright (c) 2018-2099, Chill Zhuang 庄骞 (bladejava@qq.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springblade.modules.restaurant.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.modules.restaurant.entity.CustomerSituation;
import org.springblade.modules.restaurant.excel.CustomerSituationExcel;
import org.springblade.modules.restaurant.mapper.CustomerSituationMapper;
import org.springblade.modules.restaurant.service.ICustomerSituationService;
import org.springblade.modules.restaurant.vo.CustomerSituationVO;
import org.springblade.modules.system.service.IDictService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 客情信息 服务实现类
 *
 * @author Blade
 * @since 2025-01-21
 */
@Service
@AllArgsConstructor
public class CustomerSituationServiceImpl extends BaseServiceImpl<CustomerSituationMapper, CustomerSituation> implements ICustomerSituationService {
	private final IDictService dictService;

	@Override
	public IPage<CustomerSituationVO> selectCustomerSituationPage(IPage<CustomerSituationVO> page, CustomerSituationVO customerSituation) {
		return page.setRecords(baseMapper.selectCustomerSituationPage(page, customerSituation));
	}

	@Override
	public List<CustomerSituationExcel> export(List<CustomerSituation> commoditySummaryList) {
		if (commoditySummaryList != null && !commoditySummaryList.isEmpty()) {
			return commoditySummaryList.stream().map(item -> {
				CustomerSituationExcel customerSituationExcel = new CustomerSituationExcel();
				BeanUtil.copyProperties(item, customerSituationExcel);

				// 字典值转换
				String timeSlot = dictService.getValue("customer_time_type", Integer.valueOf(item.getTimeSlot()));
				customerSituationExcel.setTimeSlot(timeSlot);
				String guestType = dictService.getValue("customer_guest_type", item.getGuestType());
				customerSituationExcel.setGuestType(guestType);
				String dicSex = dictService.getValue("sex", item.getSex());
				customerSituationExcel.setSex(StrUtil.isEmpty(dicSex) ? "未知" : dicSex);
				customerSituationExcel.setPaymentMethod(dictService.getValue("customer_payment_method", item.getPaymentMethod()));
				customerSituationExcel.setEntertain(dictService.getValue("customer_entertain", item.getEntertain()));
				return customerSituationExcel;
			}).toList();
		}
		return List.of();
	}

}
